<template>
  <div class="myMenu">
    <el-row class="tac">
      <el-col>
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#20222A"
          active-text-color="#FF5274"
          text-color="#fff"
          unique-opened
          >
          <menuItem v-for="(item, n) in menus" :item="item" :navIndex="String(n)" :key="n"></menuItem>
        </el-menu>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { MENUS } from '@/data/menusData.js';
export default {
  name: 'myMenu',
  components: {
    menuItem: () => import('./menuItem')
  },
  data() {
    return {
      menus: MENUS.admin
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    selectPages(categoryName, url) {
      console.log(categoryName, url)
    }
  },
  mounted() {
    //触发菜单更新
    this.$on('updataMenu', this.getDataMenu);
  },
  beforeDestroy() {
    //及时销毁，防止内存泄漏
    this.$off('updataMenu', this.getDataMenu);
  }
}
</script>

<style scoped lang="scss">
  .myMenu {
    width: 200px;
    height: 100%;
    @include sColor(bg, bg20222A);
    position: fixed;
    left: 0;
    overflow: auto;
    .el-menu {
      border-right: 0;
    }
  }
</style>
